/*******************************************************************************
 * Copyright 2011 @ Kapil Viren Ahuja
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.kapil.framework.test.database;

import junit.framework.Assert;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.testng.annotations.Test;

import com.kapil.framework.database.IDatabaseSetup;
import com.kapil.framework.logger.ILogger;
import com.kapil.framework.logger.LogFactory;
import com.kapil.framework.test.core.BaseTestCase;

/**
 * <p>
 * Base class for all other test cases in the application. This class provides the following functionalities:
 * <ol>
 * <li>Loads Spring's base context</li>
 * <li>Loads all the data in to the Database</li>
 * <li>Method to loads beans from Spring Context</li>
 * </ol>
 * </p>
 */

public class MySQLDatabaseSetupTestCase extends BaseTestCase
{
    private static final ILogger LOGGER = LogFactory.getInstance().getLogger(MySQLDatabaseSetupTestCase.class);


    @Test
    public void testDatabsaeBaseSetup()
    {
        IDatabaseSetup setup = super.getDatabaseSetupBean();
        setup.setupDatabase();
    }


    @Test
    public void testDatabaseSetupWithoutFiles()
    {
        try
        {
            IDatabaseSetup setup = (IDatabaseSetup) super.getBean("databaseSetupWithoutFiles");
            setup.setupDatabase();

            // We expect an exception so if we do not, we will fail this test
            Assert.fail();
        }
        catch (Exception ex)
        {
            LOGGER.error(ExceptionUtils.getFullStackTrace(ex));
        }
    }


    @Test
    public void testDatabaseSetupWithInvalidFiles()
    {
        try
        {
            IDatabaseSetup setup = (IDatabaseSetup) super.getBean("databaseSetupWithInvalidFiles");
            setup.setupDatabase();
            
            // We expect an exception so if we do not, we will fail this test
            Assert.fail();
        }
        catch (Exception ex)
        {
            LOGGER.error(ExceptionUtils.getFullStackTrace(ex));
            // We expect an exception so if we do, we will pass this test
        }
    }

    
    @Test
    public void testDatabaseSetupWithDiskLocation()
    {
            IDatabaseSetup setup = (IDatabaseSetup) super.getBean("databaseSetupWithDiskLocation");
            setup.setupDatabase();
    }
    
    
    @Test
    public void testDatabaseSetupWithDiskLocationAndWithoutFiles()
    {
        try
        {
            IDatabaseSetup setup = (IDatabaseSetup) super.getBean("databaseSetupWithDiskLocationAndWithoutFiles");
            setup.setupDatabase();

            // We expect an exception so if we do not, we will fail this test
            Assert.fail();
        }
        catch (Exception ex)
        {
            LOGGER.error(ExceptionUtils.getFullStackTrace(ex));
        }
    }

    
    
    @Test
    public void testDatabaseSetupWithDisklocationAndInvalidFiles()
    {
        try
        {
            IDatabaseSetup setup = (IDatabaseSetup) super.getBean("databaseSetupWithDisklocationAndInvalidFiles");
            setup.setupDatabase();
            
            // We expect an exception so if we do not, we will fail this test
            Assert.fail();
        }
        catch (Exception ex)
        {
            LOGGER.error(ExceptionUtils.getFullStackTrace(ex));
            // We expect an exception so if we do, we will pass this test
        }
    }
}
